package apis

import (
	"go-admin/app/admin/service"
	"go-admin/app/admin/service/dto"
	"go-admin/config"

	"github.com/gin-gonic/gin"
)

// PlayVideo 播放视频
// @Summary 播放视频
// @Description 播放视频
// @Tags 音视频
// @Param id path int true "id"
// @Success 200 {object} response.Response	"{"code": 200, "message": "播放成功"}"
// @Router /api/v1/sys-device/play/{id} [get]
// @Security Bearer
func (e SysDevice) PlayVideo(c *gin.Context) {
	s := service.SysDevice{}
	req := dto.SysChannelPlayReq{}
	err := e.MakeContext(c).
		MakeOrm().
		Bind(&req).
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}
	req.SipHost = config.ExtConfig.GoSip.Api
	req.Key = config.ExtConfig.GoSip.Key
	// 调用gosip接口
	err = s.GetRealTimePlayUrl(&req)
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}

	e.OK(req.Url, "播放成功")
}

// Control 控制设备
// @Summary 控制设备
// @Description 控制设备
// @Tags 设备
// @Param id path int true "id"
// @Param data body dto.SysDeviceControlReq true "body"
// @Success 200 {object} response.Response	"{"code": 200, "message": "控制成功"}"
// @Router /api/v1/sys-device/control/{id} [post]
// @Security Bearer
func (e SysDevice) Control(c *gin.Context) {
	s := service.SysDevice{}
	req := dto.SysDeviceControlReq{}
	err := e.MakeContext(c).
		MakeOrm().
		Bind(&req).
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}
	req.SipHost = config.ExtConfig.GoSip.Api
	req.Key = config.ExtConfig.GoSip.Key
	// 调用gosip接口
	err = s.Control(&req)
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}

	e.OK(req, "控制成功")
}
